package models

import "time"

/**
	互推匹配记录
 */
type UserInterPushRecord struct {
	ID           int `gorm:"primary_key"json:"id"`
	InterpushId       int `json:"interpush_id"`
	MaterialId int `json:"meterial_id"`
	IsShare int `json:"is_share"`
	ShareTime time.Time `json:"share_time"`
	TargetInterpushId int `json:"target_interpush_id"`
	TargetMeterialId int `json:"target_meterial_id"`
	TargetIsShare int `json:"target_is_share"`
	TargetShareTime time.Time `json:"target_share_time"`

}

/**
	用户互推信息表
 */
func (u *UserInterPushRecord) TableName() string {
	return "user_interpush_record"
}

func (i *UserInterPushRecord) Get() (*UserInterPushRecord, error) {
	var u UserInterPushRecord

	err := DB.Model(i).Where("interpush_id = ? and is_share = ?", i.InterpushId, i.IsShare).Find(&u).Error

	if err != nil {
		return nil, err
	}

	return &u, nil
}

func (i *UserInterPushRecord) GetPassive() (*UserInterPushRecord, error) {
	var u UserInterPushRecord

	err := DB.Model(i).Where("target_interpush_id = ? and target_is_share = ?", i.TargetInterpushId, i.TargetIsShare).Find(&u).Error

	if err != nil {
		return nil, err
	}

	return &u, nil
}